# clustering/Makefile
# Distriibutions
# Matthew Jee
# mcjee@ucsc.edu

NEEDS_DEPENDENCIES = ${filter clean,${MAKECMDGOALS}}

GENERATOR         = cluster_gen
CLU_RENDERER      = cluster_render
PATH_RENDERER     = path_render

GENERATOR_SRC     = io.cpp cluster_gen.cpp clustering.cpp
GENERATOR_OBJ     = $(GENERATOR_SRC:%.cpp=%.o)

CLU_RENDERER_SRC  = io.cpp cluster_render.cpp meshgeneration.cpp
CLU_RENDERER_OBJ  = $(CLU_RENDERER_SRC:%.cpp=%.o)

PATH_RENDERER_SRC = io.cpp path_render.cpp meshgeneration.cpp
PATH_RENDERER_OBJ = $(PATH_RENDERER_SRC:%.cpp=%.o)

UNAME             = $(shell uname -s)
COMPILE_OPTIONS   = -Wall -Wextra -pedantic

ifeq "$(UNAME)" "Darwin"
COMPILER          = clang++
LINKER            = clang++
LIBRARIES         = ../renderer/mjrender.a -lglfw3
FRAMEWORKS        = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
COMPILE_CMD       = $(COMPILER) $(COMPILE_OPTIONS)
GRAPHICS_LINK_CMD = $(LINKER) $(FRAMEWORKS)
LINK_CMD          = $(LINKER)
endif

ifeq "$(UNAME)" "Linux"
COMPILER          = g++
LINKER            = g++
LIBRARIES         = ../renderer/mjrender.a -lglfw3
COMPILE_CMD       = $(COMPILER) $(COMPILE_OPTIONS)
LINK_CMD          = $(LINKER)
GRAPHICS_LINK_CMD = $(LINKER)
endif

all: $(GENERATOR) $(RENDERER)

$(GENERATOR): $(GENERATOR_OBJ)
	$(LINK_CMD) -o $(GENERATOR) $(GENERATOR_OBJ)

$(CLU_RENDERER): $(CLU_RENDERER_OBJ)
	$(GRAPHICS_LINK_CMD) -o $(CLU_RENDERER) $(CLU_RENDERER_OBJ) $(LIBRARIES)

$(PATH_RENDERER): $(PATH_RENDERER_OBJ)
	$(GRAPHICS_LINK_CMD) -o $(PATH_RENDERER) $(PATH_RENDERER_OBJ) $(LIBRARIES)

%.o: %.cpp
	$(COMPILE_CMD) -o $@ -c $<

clean:
	@echo Cleaning Distributions =============================================
	- rm $(GENERATOR_OBJ) $(CLU_RENDERER_OBJ) $(PATH_RENDERER_OBJ) $(GENERATOR) $(RENDERER) dependencies

dependencies:
	$(COMPILER) -MM $(GENERATOR_SRC) $(PATH_RENDERER_SRC) $(CLU_RENDERER_SRC) > dependencies

ifeq "$(NEEDS_DEPENDENCIES)" ""
include dependencies
endif
